class Solution
{
public:
    Solution() {}
    int maxDistToClosest(vector<int> &seats)
    {
        int len = seats.size();
        int leftSpace = 0;
        int rightSpace = 0;
        int maxMiddleSpace = 1;
        for (int i = 0; i < len; ++i)
        {
            if (seats[i])
            {
                break;
            }
            else
            {
                ++leftSpace;
            }
        }

        for (int i = len - 1; i >= 0; --i)
        {
            if (seats[i])
            {
                break;
            }
            else
            {
                ++rightSpace;
            }
        }

        int middleSpace = 1;
        for (int i = leftSpace; i < len - rightSpace; ++i)
        {
            if (seats[i])
            {
                if (middleSpace > maxMiddleSpace)
                {
                    maxMiddleSpace = middleSpace;
                }
                middleSpace = 1;
            }
            else
            {
                ++middleSpace;
            }
        }

        return max(maxMiddleSpace / 2, max(leftSpace, rightSpace));
    }
};